<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="车辆ID，关联到车辆信息表" prop="vehicleId">
        <el-input
          v-model="queryParams.vehicleId"
          placeholder="请输入车辆ID，关联到车辆信息表"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="入库时间" prop="storageDateTime">
        <el-date-picker
          clearable
          v-model="queryParams.storageDateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择入库时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出库时间" prop="deliveryDateTime">
        <el-date-picker
          clearable
          v-model="queryParams.deliveryDateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出库时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="车牌号" prop="Licenseplate">
        <el-input
          v-model="queryParams.Licenseplate"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="Ordernumber">
        <el-input
          v-model="queryParams.Ordernumber"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:storagemanagement:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:storagemanagement:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="storagemanagementList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="出入库记录ID，唯一标识符" align="center" prop="storageId" /> -->
      <el-table-column
        label="停车类型"
        align="center"
        prop="vehicleOwnerType"
      />
      <el-table-column label="操作类型" align="center" prop="operationTypeds" />
      <el-table-column
        label="入库时间"
        align="center"
        prop="storageDateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.storageDateTime, formatDateTime)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="出库时间"
        align="center"
        prop="deliveryDateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.deliveryDateTime, formatDateTime)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" prop="vehicleInfo" />
      <!-- <el-table-column label="车辆类型" align="center" prop="Vehicletype" /> -->
      <el-table-column label="订单编号" align="center" prop="rnumber" />
      <el-table-column label="优惠卷id" align="center" prop="eofferid" />
      <el-table-column label="金额" align="center" prop="amount" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="listName(true, scope.row.storageId)"
            icon="el-icon-postcard"
            v-hasPermi="['system:storagemanagement:query']"
            style="margin-left: 16px"
          >
            详细信息
          </el-button>

          <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:storagemanagement:add']"
          >新增</el-button>

          <!-- <el-button
            @click="payOrder()"
            style="margin-left: 16px"
          >
            点击支付
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- <el-drawer
      title="入库信息"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
    >
      <span style="width: 10px; height: 10px" :data="spacequantityList" >
        <el-card class="box-card"  slot="header"  v-for="(item, index) in spacequantityList.rows
" :key="index" >
          <div >
    <span>入库信息</span>
  </div>

  <div>车牌号&emsp;&emsp;&emsp;设备号&emsp;&emsp;&emsp;时间&emsp;&emsp;</div>
  <span>{{item.storageId}}&emsp;{{item.Ordernumber}}&emsp;{{item.storageDateTime}}</span>
        </el-card>
      </span>
    </el-drawer> -->
    <el-drawer
      title="订单信息"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
      :data="spacequantityList"
    >
      <div>
        <el-card class="box-card">
          <div style="background-color: #f0f0f0; width: 100%">
            <span>入库信息</span>
          </div>
          <div>
            ___________________________________________________________________________________
          </div>
          <div>
            车牌号:&emsp;{{
              spacequantityList.vehicleInfo
            }}&emsp;_订单编号:&emsp;{{
              spacequantityList.rnumber
            }}&emsp;&emsp;_入库时间:&emsp;{{
              spacequantityList.storageDateTime
            }}&emsp;
          </div>
        </el-card>
        <el-card class="box-carx">
          <div style="background-color: #f0f0f0; width: 100%">
            <span>支付信息</span>
          </div>
          <button @click="getAli()">点击支付</button>
          <div>
            ___________________________________________________________________________________
          </div>
          <div>
            <div>
              车牌号:&emsp;{{
                spacequantityList.vehicleInfo
              }}&emsp;车辆类型:&emsp;{{
                spacequantityList.vehicleOwnerType
              }}&emsp;&emsp;应收金额:&emsp;{{ spacequantityList.amount }}&emsp;
            </div>
            <span margin="asd">.</span>
            <div>
              订单金额:&emsp;{{ spacequantityList.amount }}&emsp;_|{{
                spacequantityList.stoptime
              }}&emsp;_|出库时间:{{ spacequantityList.deliveryDateTime }}&emsp;
            </div>
          </div>
        </el-card>
      </div>
    </el-drawer>

    <!-- 添加或修改出入库管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">





        <el-form-item
          label="车牌号"
          prop="Licenseplate"
        >
          <el-input
            v-model="form.Licenseplate"
            placeholder="请输入车牌号  "
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStoragemanagement,
  getStoragemanagement,
  delStoragemanagement,
  addStoragemanagement,
  updateStoragemanagement,
  getAlipay,
} from "@/api/system/storagemanagement";

import moment from "moment";
export default {
  name: "Storagemanagement",
  data() {
    return {
      drawer: false,
      direction: "ttb",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],

      spacequantityList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出入库管理表格数据
      storagemanagementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storageId: null,
        vehicleId: null,
        vehicleOwnerType: null,
        operationType: null,
        Licenseplate: null,
        Vehicletype: null,
        operationTypeds: null,
        storageDateTime: null,
        deliveryDateTime: null,
        vehicleInfo: null,
        rnumber: null,
        eofferid: null,
        amount: null,
        queryParams2: [
          {
            pageNum: 1,
            pageSize: 10,
            storageId: 3,
            vehicleId: null,
            vehicleOwnerType: null,
            operationType: null,
            Licenseplate: null,
            Vehicletype: null,
            operationTypeds: null,
            storageDateTime: null,
            deliveryDateTime: null,
            vehicleInfo: null,
            rnumber: null,
            eofferid: null,
            amount: null,
          },
        ],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  filters: {
    formatDateTime(value) {
      return moment(value).format("YYYY-MM-DD HH:mm:ss"); // 使用正确的占位符
    },
  },
  created() {
    this.getList();
  },
  methods: {
    handleClose(done) {
      done();
    },
    /** 查询出入库管理列表 */
    getList() {
      this.loading = true;
      listStoragemanagement(this.queryParams).then((response) => {
        this.storagemanagementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        // storageId: null,
        // vehicleId: null,
        // vehicleOwnerType: null,
        // operationType: null,
        Licenseplate: null,
        // Vehicletype: null,
        // operationTypeds: null,
        // storageDateTime: null,
        // deliveryDateTime: null,
        // vehicleInfo: null,
        // rnumber: null,
        // eofferid: null,
        // amount: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.storageId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加出入库管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const storageId = row.storageId || this.ids;
      getStoragemanagement(storageId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出入库管理";
      });
    },
    // 详细信息
    listName(drawer, maindid) {
      this.drawer = drawer;
      console.log(maindid);
      if (maindid != null) {
        this.queryParams.queryParams2[0].storageId = maindid;
      }
      console.log(this.queryParams);
      getStoragemanagement(this.queryParams.queryParams2[0]).then(
        (response) => {
          console.log(response.data);
          this.spacequantityList = response.data;
          console.log(this.spacequantityList);
        }
      );
    }, //
    getAli() {
      // 假设你想跳转到端口号为8081的地址

      window.location.href =
        "http://localhost:8080/alipay/pay?rnumber=" +
        this.spacequantityList.rnumber +
        "&amount=" +
        this.spacequantityList.amount +
        "&vehicleInfo=" +
        this.spacequantityList.vehicleInfo;
      // window.open()
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.storageId != null) {
            updateStoragemanagement(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStoragemanagement(this.form).then((response) => {
              if(response.data){
              }
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const storageIds = row.storageId || this.ids;
      this.$modal
        .confirm('是否确认删除出入库管理编号为"' + storageIds + '"的数据项？')
        .then(function () {
          return delStoragemanagement(storageIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/storagemanagement/export",
        {
          ...this.queryParams,
        },
        `storagemanagement_${new Date().getTime()}.xlsx`
      );
    },
    payOrder() {
      let _this = this;
      this.$ajax
        .post(process.env.VUE_APP_SERVER + "/store/order/aliPay", {})
        .then((response) => {
          let resp = response.data;
          if (resp.code === 0) {
            // 添加之前先删除一下，如果单页面，页面不刷新，添加进去的内容会一直保留在页面中，二次调用form表单会出错
            const divForm = document.getElementsByTagName("div");
            if (divForm.length) {
              document.body.removeChild(divForm[0]);
            }
            const div = document.createElement("div");
            div.innerHTML = resp.data; // data就是接口返回的form 表单字符串
            document.body.appendChild(div);
            //document.forms[0].setAttribute('target', '_blank');// 新开窗口跳转
            document.forms[0].submit();
          } else {
            _this.$message.error(resp.msg);
          }
        });
    },
    payReturn() {
      let _this = this;
      if (this.$route.query && this.$route.query.out_trade_no) {
        // 支付回调
        console.log("进入回调...");
        console.log("交易号：" + this.$route.query.out_trade_no);
        this.$ajax
          .post(process.env.VUE_APP_SERVER + "/store/order/aliPay/success", {
            no: this.$route.query.out_trade_no,
          })
          .then((response) => {
            let resp = response.data;
            if (resp.code === 0) {
              _this.$message.success(resp.msg);
            } else {
              _this.$message.error(resp.msg);
            }
          });
      }
    },
  },
};
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 600px;
  height: 150px;
}
.dna {
  height: 40px;
}
.box-carx {
  height: 150px;
  width: 600px;
}
.ellipse-border {
  /* 设定固定宽度和高度 */
  width: 200px; /* 例如宽度为200px */
  height: 200px; /* 例如高度为100px，形成长方形 */
  border: 2px solid #333; /* 设置边框颜色和粗细 */
  background-color: transparent; /* 确保没有背景颜色 */
  /* 可以在这里添加其他的样式属性，比如margin, padding等 */
}
</style>
